package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.EnzymeActivity;
import com.ruoyi.system.service.IEnzymeActivityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 酶活性Controller
 * 
 * @author ruoyi
 * @date 2024-03-20
 */
@Controller
@RequestMapping("/system/activity")
public class EnzymeActivityController extends BaseController
{
    private String prefix = "system/activity";

    @Autowired
    private IEnzymeActivityService enzymeActivityService;

    @RequiresPermissions("system:activity:view")
    @GetMapping()
    public String activity()
    {
        return prefix + "/activity";
    }

    /**
     * 查询酶活性列表
     */
    @RequiresPermissions("system:activity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EnzymeActivity enzymeActivity)
    {
        startPage();
        List<EnzymeActivity> list = enzymeActivityService.selectEnzymeActivityList(enzymeActivity);
        return getDataTable(list);
    }

    /**
     * 导出酶活性列表
     */
    @RequiresPermissions("system:activity:export")
    @Log(title = "酶活性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EnzymeActivity enzymeActivity)
    {
        List<EnzymeActivity> list = enzymeActivityService.selectEnzymeActivityList(enzymeActivity);
        ExcelUtil<EnzymeActivity> util = new ExcelUtil<EnzymeActivity>(EnzymeActivity.class);
        return util.exportExcel(list, "酶活性数据");
    }

    /**
     * 新增酶活性
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存酶活性
     */
    @RequiresPermissions("system:activity:add")
    @Log(title = "酶活性", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EnzymeActivity enzymeActivity)
    {
        return toAjax(enzymeActivityService.insertEnzymeActivity(enzymeActivity));
    }

    /**
     * 修改酶活性
     */
    @RequiresPermissions("system:activity:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EnzymeActivity enzymeActivity = enzymeActivityService.selectEnzymeActivityById(id);
        mmap.put("enzymeActivity", enzymeActivity);
        return prefix + "/edit";
    }

    /**
     * 修改保存酶活性
     */
    @RequiresPermissions("system:activity:edit")
    @Log(title = "酶活性", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EnzymeActivity enzymeActivity)
    {
        return toAjax(enzymeActivityService.updateEnzymeActivity(enzymeActivity));
    }

    /**
     * 删除酶活性
     */
    @RequiresPermissions("system:activity:remove")
    @Log(title = "酶活性", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(enzymeActivityService.deleteEnzymeActivityByIds(ids));
    }
}
